package com.xiezc.util;


import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.*;

/**
 * author: Administrator
 * createTime: 2017/9/12 0012 下午 23:18
 */
public class XUtil {

    public static boolean stop = false;

    private static ExecutorService threadPoolExecutor;

    public static ExecutorService getThreadPool() {
        if (threadPoolExecutor == null) {
            threadPoolExecutor = Executors.newCachedThreadPool();
        }
        return threadPoolExecutor;
    }

    /**
     * 处理对应的url
     *
     * @throws MalformedURLException
     */
    public static String dealUrl(String url, String previousUrl) {
        if (url.startsWith("http:") || url.startsWith("https:")) {
            return url;
        }
        if (url.startsWith("/")) {
            URL urls;
            try {
                urls = new URL(previousUrl);
            } catch (MalformedURLException e) {
                throw new XException(e);
            }
            return urls.getProtocol() + "://" + urls.getHost() + url;
        }
        return previousUrl + "/" + url;
    }
}
